<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="com.ncp.model.entity.cart.CartBean"%>
<jsp:useBean id="cart" scope="session" class="com.ncp.model.biz.cart.ShoppingCart"/>
<jsp:useBean id="cartbean" scope="session" class="com.ncp.model.entity.cart.CartBean"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
  <head>
    <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>确认订单信息</title>
    
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="css/common.css" type="text/css" rel="stylesheet" />
	<link href="css/list.css" type="text/css" rel="stylesheet" />
	<link href="css/sure.css" type="text/css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="css/cart.css">
	<%--<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
	--%><script src="js/cart/cart.js" type="text/javascript" charset="UTF-8"></script>
	<script type="text/javascript" src="/NCP/js/register/jsAddress.js"></script>
	<script language="JavaScript" type="text/javascript" src="/NCP/js/cart/order_ck.js" charset="UTF-8"></script>
	
	<script type="text/javascript">
		
	//AJAX添加新地址
		var xmlHttp;
		function newAddress(){
			
			var name = document.getElementById("receiveName").value;
			var address = document.getElementById("province").value + document.getElementById("city").value + document.getElementById("area").value + document.getElementById("street").value;
			var zip = document.getElementById("zip").value;
			var phone = document.getElementById("phone").value;
			var mobile = document.getElementById("mobile").value;
			var email = document.getElementById("email").value;
			
			createXmlHttp();
			
			var param = "name="+ name +"&address="+ address +"&zip="+ zip +"&phone="+ phone +"&mobile="+ mobile +"&email="+ email;
			//alert(param);
    		
			xmlHttp.open("POST", "ManageAddressServlet", true);
    		
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");   		
    		
    		xmlHttp.onreadystatechange = function showAddress(){
			if(xmlHttp.readyState == 4){
				//hiddenAdd();
				var v = xmlHttp.responseText;
				alert(v);
				//document.getElementById("inputAdd").value = xmlHttp.responseText;
				document.getElementById("address").innerHTML += "<input type='radio' name='addressID' value="+ v +" checked='true'><div><p>"+ name +"</p><p>"+ mobile +"</p><p>"+ address +"</p><p>"+ zip +"</p></div></input>";
				alert("ok");
				//alert(document.getElementById("inputAdd").value);
				//hiddenAdd();
				//document.getElementById("addresses").appendChild("<div id="+ v +" onclick=javascript: setAddress("+ v +", "+ v +")>"+ name +"<br/></div>");
			}
		};
			//xmlHttp.setRequestHeader("contentType","text/html;charset=utf-8");
    		xmlHttp.send(param);
		}
		
		function createXmlHttp() {
		    //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
			 try
			    {
			   // Firefox, Opera 8.0+, Safari
			    xmlHttp=new XMLHttpRequest();
			    }
			 catch (e)
			    {
		
			  // Internet Explorer
			   try
			      {
			      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			      }
			   catch (e)
			      {
		
			      try
			         {
			         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			         }
			      catch (e)
			         {
			         alert("您的浏览器不支持AJAX！");
			         return false;
			         }
			      }
			    }
		}
		function displayAdd(){
			
			//document.getElementById("newAddress").innerHTML = "";
						
		}
		
	</script>
	
	<!-- 控制只有登录后才能访问该页面 -->
	
	<%@ include file="../common/checklogin.jsp"%>
	
  </head>
  
<body onload="javascript: hiddenAdd()">
<div id="allpage">
	<jsp:include flush="true" page="../index/head.jsp"></jsp:include>
	<div id="main" style="padding:0 20px;width:938px;">
		<div id="position">
			<p>您的位置：<a href="#">首页</a>&emsp;>&emsp;我的购物车</p>
		</div>
		
		<div id="step">
			<ul>
				<li class="left">1.查看购物车</li>
				<li class="left current">2.确认订单信息</li>
				<li class="left">3.付款到支付宝</li>
				<li class="left">4.确认收货</li>
				<li class="left">5.评价</li>
			</ul>
		</div>
		<div style="clear:both"></div>
		<div id="display" style="padding:0 20px;">
			<div id="items">
				<div class="gray_bar"><p style="line-height:28px;">订单信息</p></div>
				<%
    					if(cart.getProductNum()!=0){
    					Map<String,CartBean> cartMap = null;
    					cartMap = cart.getCartMap();
    					CartBean cartBean = null;
    					Iterator<String> hmkey = cartMap.keySet().iterator();
    					while(hmkey.hasNext()){
    						cartBean = cartMap.get(hmkey.next());
    				%>
    		<table style=" border:1px solid #DDD;">
				<tr class="line" style="line-height:26px;">
    				<!-- 显示产品图片 -->
					<td style="border-right:1px solid #DDD; padding:25px;">
						<div class="picture">
							<a href="#">
								<img style="width:120px; height:120px;" src="<%=cartBean.getProductImage() %>"/>
							</a>
						</div>
					</td>
					<td style=" padding:25px; width:200px; overflow:hidden; border-right:1px solid #DDD;">
						<p>
							<!-- 商品名称 -->
							<span class="info_font"><%=cartBean.getProductName() %></span>
							<div style="clear:both"></div>
							<span class="trade_font"></span>
						</p>
						<div style="clear:both"></div>
						<p>
							<span class="gray_font">￥</span>
							<!-- 商品单价 -->
							<span class="red_font"><%=cartBean.getRetailPrice() %></span>
							<span class="gray_font through">￥<%=cartBean.getMarketprice() %></span>
							<div style="clear:both"></div>
							<span class="gray_font">运费0.0</span>
						</p>
						<div style="clear:both"></div>
					</td>
					<td style=" border-right:1px solid #DDD; text-align:center; width:130px; line-height:150px;">0（积分）</td>
					<!-- 商品数量 -->
					<td style=" border-right:1px solid #DDD; text-align:center; width:130px; line-height:150px;"><%=cartBean.getProductNumOfCart() %></td>
					<!-- 该商品价格小计 -->
					<td style=" border-right:1px solid #DDD; text-align:center; width:130px; line-height:150px;"><%=(cartBean.getRetailPrice() * cartBean.getProductNumOfCart())%> 元（价格）</td>
					<td style=" width:130px;">
						<form style="text-align:center;">
							<!-- <input type="submit" value="删除" onclick="" style="cursor:pointer;" />  -->
						</form>
					</td>
				</tr>
			</table>
			
					<%
    					}
    	 			}else{
    	 				out.print("<script language=javascript>alert('你还没有选择任何商品！');window.location.replace('http://127.0.0.1:8080/NCP/index.jsp');</script>");
    	 			}
    	  			%>
				
					
					<div style="line-height:24px; border-bottom:1px solid #DDD;clear:both;padding:20px 0;">
						数量总计：<%=cart.getProductNum()%>
	    	 			应付总额：<%=cart.getTotalprice() %>
    	 			</div>
    	 			<form id="orderinfo" name="orderinfo" action="CommitOrderServlet" method="post" style="padding:20px 0; border-bottom:1px solid #DDD; line-height:24px;">
    	 			
    	 			<div id="address">				    	
				  		
				    	<c:if test="${not empty receivers}">
				    		已有收货地址<br/>
				    		
				    		<c:forEach items="${receivers}" var="receiver">
				    			<input type="radio" name="addressID" value="${receiver.id}">
				    			<div>
				    				<p>${receiver.name }</p>
				    				<p>${receiver.mobile }</p>
				    				<p>${receiver.address }</p>
				    				<p>${receiver.zip }</p> 				
				    			</div>
				    			</input>
				    		</c:forEach>
				    	</c:if>
				    	
				    	
				    </div>	
				    	<button onclick="javascript: displayAdd()">使用新地址</button>
				    
				    <div id="newAddress" >
					
						<p>收货信息：</p>
						<p>姓&emsp;&emsp;名：<input style="border:1px solid #DDD;" name="receive_name" id="receiveName" type="text" onBlur="checkUserName(this)"/><span id=username_notice >*</span></p>
						<p>
							省份：<select name="province" id="province" style="border:1px solid #DDD; width:150px;"></select>
							城市：<select name="city" id="city" style="border:1px solid #DDD; width:150px;"></select>
							区：<select name="area" id="area" style="border:1px solid #DDD; width:150px;"></select>
						</p>
						<script type="text/javascript" language="javascript">
							var pccs=new PCCS("pccs",["province","city","area"],["请选择","请选择","请选择"],["上海","上海","浦东新区"]);
							pccs.init();
						</script>
						<p>详细地址：<input id="street" style="border:1px solid #DDD;" name="detailaddress" type="text" onBlur="checkAddress(this)"/><span id=address_notice >*</span></p>
						<p>邮&emsp;&emsp;编：<input id="zip" style="border:1px solid #DDD;" name="receive_zip" type="text" onBlur="checkZip(this)"/><span id=zip_notice >*</span></p>
						<p>固定电话：<input id="phone" style="border:1px solid #DDD;" name="receive_phone" type="text" /></p>
						<p>移动电话：<input id="mobile" style="border:1px solid #DDD;" name="receive_mobile" onBlur="checkTel(this)" type="text" /><span id=tel_notice >*</span></p>
						<p>电子邮件：<input id="email" style="border:1px solid #DDD;" name="receive_email" type="text" onBlur="checkEmail(this)" /><span id=email_notice >*</span></p>
						<p><button onclick="javascript: newAddress()">确定</button></p>
					 	
					</div>	
					
						<p>送货方式：</p>
						<p>
							<label><input name="logistics_type" type="radio" checked="checked" value="EXPRESS"/>快递</label>
							<label><input name="logistics_type" type="radio" value="POST"/>平邮</label>
							<label><input name="logistics_type" type="radio" value="EMS"/>EMS</label>
						</p>
						<p>支付方式：</p>
						<p>
							<label><input name="pay_method" type="radio" checked="checked" value="alipay"/>支付宝</label>
							<label><input name="pay_method" type="radio" value="bank"/>网上银行</label>
						</p>
						<p>应付总额：<%=cart.getTotalprice() %> 元</p>
						<input name="continueshopping" type="button" value="继续购物" onclick="" style="cursor:pointer;"/>
						<input name="ordersubmit" type="submit" value="提交订单" onsubmit=""  style="cursor:pointer;"/>
					</form>
					
					<div style=" border-bottom:1px solid #DDD;clear:both"></div>
			</div>
		</div>
	</div>
	
	<div id="slice"></div>
	
	<jsp:include flush="true" page="../index/foot.jsp"></jsp:include>
	
</div>

</body>
</html>
